<template>
  <el-dialog
    v-if="visible"
    v-el-drag-dialog
    :title="type === 'add' ? '新增商品' : '编辑商品'"
    :visible.sync="visible"
    width="750px"
    @close="reset"
  >
    <el-tabs v-model="activeName" type="card">
      <el-tab-pane label="商品信息" name="first">
        <el-form ref="dataForm" class="form" :rules="rules" :model="temp" label-position="right" label-width="130px">
          <el-form-item style="width: 100%;" label="类型:">
            <span>{{ currentGoodsType.gtName }}</span>
          </el-form-item>
          <el-form-item label="编码:" prop="goodsCode">
            <el-input v-model="temp.goodsCode" placeholder="请输入" :disabled="type==='edit'" :maxlength="10" clearable @input="temp.goodsCode=temp.goodsCode.replace(/[^a-z0-9_]/g,'')">
              <el-button v-if="type === 'add'" slot="append" class="append-search" @click.prevent="getCode">获取</el-button>
            </el-input>
          </el-form-item>
          <el-form-item label="单位:" prop="unitId">
            <el-select v-model="temp.unitId" clearable placeholder="请选择">
              <el-option v-for="item in unitIdMap" :key="item.value" :label="item.desc" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item style="width: 100%;" label="名称:" prop="goodsName">
            <el-input v-model="temp.goodsName" :maxlength="50" clearable placeholder="请输入" />
          </el-form-item>
          <el-form-item label="别名:" prop="aliasName">
            <el-input v-model="temp.aliasName" :maxlength="50" clearable placeholder="请输入" />
          </el-form-item>
          <el-form-item label="体积(m³):" prop="cubage">
            <el-input-number v-model="temp.cubage" :controls="false" :min="0" :max="99999999" :pression="0" clearable placeholder="请输入" style="width: 100%;" />
          </el-form-item>
          <el-form-item label="重量(kg):" prop="weight">
            <el-input-number v-model="temp.weight" :controls="false" :min="0" :max="99999999" :pression="2" clearable placeholder="请输入" style="width: 100%;" />
          </el-form-item>
          <el-form-item label="型号:" prop="specId">
            <el-select v-model="temp.specId" filterable clearable placeholder="请选择">
              <el-option v-for="item in specListAll" :key="item.specId" :label="item.specName" :value="item.specId" />
            </el-select>
          </el-form-item>
          <el-form-item label="计价方式:" prop="pricingMode">
            <el-select v-model="temp.pricingMode" placeholder="请选择" @change="priceingModeChange">
              <el-option label="按包装计费" :value="1" />
              <el-option label="按单位计费" :value="2" />
            </el-select>
          </el-form-item>
          <el-form-item label="远距配送费用(元):" prop="deliveryFun">
            <el-input-number v-model="temp.deliveryFun" :controls="false" :min="0" :max="99999999" disabled placeholder="请输入" style="width: 100%;" />
          </el-form-item>
          <el-form-item label="上楼费(元):" prop="floorFun">
            <el-input-number v-model="temp.floorFun" :controls="false" :min="0" :max="99999999" disabled placeholder="请输入" style="width: 100%;" />
          </el-form-item>
          <el-form-item label="押金(元):" prop="cashPledge">
            <el-input-number v-model="temp.cashPledge" :controls="false" :min="0" :max="99999999" clearable placeholder="请输入" style="width: 100%;" />
          </el-form-item>
          <el-form-item style="width: 100%;" label="退残单价(元/kg):" prop="returnPriceType">
            <el-radio v-model="temp.returnPriceType" :label="1">按商品销售价格</el-radio>
            <el-radio v-model="temp.returnPriceType" :label="2">自定义</el-radio>
            <el-input-number v-if="temp.returnPriceType === 2" v-model="temp.returnPrice" :controls="false" :min="0" :max="99999999" :pression="2" clearable placeholder="请输入" style="width: 75%; margin-right: 10px;" />元/kg
          </el-form-item>
          <el-form-item label="商品状态:" prop="gdStatus">
            <el-select v-model="temp.gdStatus" multiple placeholder="请选择">
              <el-option v-for="item in gdStatusMap" :key="item.value" :label="item.desc" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="商品性质:" prop="gdProperty">
            <el-select v-model="temp.gdProperty" placeholder="请选择" clearable>
              <el-option v-for="item in gdPropertyMap" :key="item.value" :label="item.desc" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item v-if="currentGoodsType.gtCategory===4" label="积分兑换:" prop="exchangeFlag">
            <el-select v-model="temp.exchangeFlag" placeholder="请选择">
              <el-option label="不可兑换" :value="1" />
              <el-option label="可兑换" :value="2" />
            </el-select>
          </el-form-item>
          <el-form-item style="width: 50%;" label="营销渠道:" prop="saleMode">
            <el-select v-model="temp.saleMode" multiple placeholder="请选择">
              <el-option v-for="item in goodsChannel" :key="item.value" :label="item.desc" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item v-if="currentGoodsType.gtCategory!==4" style="width: 50%; color: red;" label-width="0" prop="csmPhone">
            *微信端渠道不支持按单位计价商品
          </el-form-item>
          <el-form-item style="width: 50%;" label="指定用户:" prop="csmType">
            <el-select v-model="temp.csmType" multiple placeholder="请选择">
              <el-option v-for="item in userTypeList" :key="item.value" :label="item.desc" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="提成:" prop="percentage" class="block">
            <el-input-number v-model="temp.percentage" :min="0" :precision="2" :controls="false" />
          </el-form-item>
          <el-form-item label="其他:" class="block">
            <el-checkbox v-model="sys_goods_edit_options_1">不统计库存</el-checkbox>
            <el-checkbox v-model="sys_goods_edit_options_2">启用空重转换</el-checkbox>
            <!--            <el-checkbox v-model="sys_goods_edit_options_3">可押</el-checkbox>-->
            <!--            <el-checkbox v-model="sys_goods_edit_options_4">可欠</el-checkbox>-->
            <el-checkbox v-model="sys_goods_edit_options_5">无需扫码</el-checkbox>
            <el-checkbox v-model="sys_goods_edit_options_6">上传照片</el-checkbox>
          </el-form-item>
          <el-form-item label="使用范围:" style="width: 50%;" prop="radio">
            <el-radio v-model="temp.radio" label="1">不限</el-radio>
            <el-radio v-model="temp.radio" label="2">自定义</el-radio>
          </el-form-item>
          <el-form-item v-show="temp.radio === '2'" style="width: 50%;" label-width="0" prop="orgIds">
            <tree-select
              v-model="temp.orgIds"
              :clearable="false"
              :check-strictly="true"
              class="tree-select"
              :popover-width="360"
              :select-params="{
                clearable: true,
                multiple: true,
                placeholder: '请选择',
                loading: $loadingPlugin.getTreeData
              }"
              :tree-params=" {
                'highlight-current': true,
                'filterable': true,
                props:{
                  value:'orgId',
                  label: 'orgName',
                  disabled: 'disabled',
                },
                data: treeData
              }"
              @checkData="doCheck"
            />
          </el-form-item>
          <el-form-item label="显示顺序:" prop="showIndex" class="block">
            <el-input-number v-model="temp.showIndex" :controls="false" :min="0" :max="99999999" :precision="0" clearable placeholder="请输入" />
          </el-form-item>
          <el-form-item label="描述:" prop="remark" class="block">
            <el-input v-model="temp.remark" type="textarea" :rows="5" :maxlength="1000" show-word-limit />
          </el-form-item>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="扩展信息" name="second">
        <el-tabs v-model="additionTab" :tab-position="'right'">
          <el-tab-pane label="图文详情" name="first">
            <fu-editor ref="fuEditor1" :content="temp.extends1" />
          </el-tab-pane>
          <el-tab-pane label="产品参数" name="second">
            <fu-editor ref="fuEditor2" :content="temp.extends2" />
          </el-tab-pane>
          <el-tab-pane label="售后保障" name="third">
            <fu-editor ref="fuEditor3" :content="temp.extends3" />
          </el-tab-pane>
          <el-tab-pane label="税务信息" name="forth">
            <el-form class="form" :model="temp" label-position="right" label-width="80px">
              <el-form-item label="商品简码:" prop="goodsShortCode">
                <el-input v-model="temp.goodsShortCode" :maxlength="11" placeholder="请输入" />
              </el-form-item>
              <el-form-item label="是否使用优惠政策" label-width="120" prop="isPreferential">
                <el-checkbox v-model="temp.isPreferential" />
              </el-form-item>
              <el-form-item label="税率标识:" prop="taxRateFlag">
                <el-select v-model="temp.taxRateFlag" placeholder="请选择">
                  <el-option v-for="item in taxRateFlagMap" :key="item.value" :label="item.desc" :value="item.value" />
                </el-select>
              </el-form-item>
              <el-form-item label="税率:" prop="taxRate">
                <el-input-number v-model="temp.taxRate" :controls="false" :min="0" :max="100" :precision="2" style="width: 90%;" placeholder="请输入" />
                %
              </el-form-item>

            </el-form>
          </el-tab-pane>
        </el-tabs>

      </el-tab-pane>

    </el-tabs>

    <div slot="footer" class="dialog-footer">
      <el-button @click="reset">
        关闭
      </el-button>
      <el-button :loading="$loadingPlugin.add || $loadingPlugin.edit" type="primary" @click="success">
        保存
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { queryMap, queryOrgCode, querySpecListAll, goodsAdd, queryGoodsDefaultData } from '@/api'
  import { mapGetters } from 'vuex'
  import getTreeData from '@/utils/jsonTree'
  import { mergeAsyncFunc } from '@/utils/mergeAsyncFunc'
  import FuEditor from '@/components/FuCkEditor'
  import treeSelect from './ElTreeSelect'
  export default {
    name: 'add',
    components: {
      FuEditor,
      treeSelect
    },
    data() {
      return {
        visible: false,
        type: 'add',
        row: {},
        activeName: 'first',
        additionTab: 'first',
        treeData: [],
        currentGoodsType: {
          gtName: ''
        },
        specListAll: [],
        unitIdMap: [],
        gdStatusMap: [],
        gdStatusMapOrigin: [],
        gdPropertyMap: [],
        goodsChannel: [
          { value: 1, desc: '呼叫中心（CRM,话务下单）' },
          { value: 2, desc: '移动端（公众号,小程序）' },
          { value: 4, desc: 'App端（代客,教客下单）' },
          { value: 8, desc: '门店（门店下单）' },
          { value: 64, desc: '企业端（PC，槽批批发）' }
        ],
        userTypeList: [],
        goodsChannelOrigin: [
          { value: 1, desc: '呼叫中心（CRM,话务下单）' },
          { value: 2, desc: '移动端（公众号,小程序）' },
          { value: 4, desc: 'App端（代客,教客下单）' },
          { value: 8, desc: '门店（门店下单）' },
          { value: 64, desc: '企业端（PC，槽批批发）' }
        ],
        taxRateFlagMap: [],
        goodsId: 0,
        sys_goods_edit_options_1: false,
        sys_goods_edit_options_2: false,
        sys_goods_edit_options_3: false,
        sys_goods_edit_options_4: false,
        sys_goods_edit_options_5: false,
        sys_goods_edit_options_6: false,
        detail: {},
        temp: {
          goodsCode: '',
          goodsName: '',
          unitId: '',
          aliasName: '',
          cubage: 0,
          weight: 0,
          percentage: 0.00,
          specId: '',
          pricingMode: 1,
          deliveryFun: 0,
          floorFun: 0,
          cashPledge: 0,
          returnPrice: 0,
          gdStatus: [],
          gdProperty: 1,
          saleMode: [],
          csmType: [],
          checkList: [],
          radio: '1',
          returnPriceType: '',
          orgIds: [],
          showIndex: 999,
          remark: '',
          exchangeFlag: 2,
          goodsShortCode: '',
          isPreferential: false,
          taxRateFlag: 1,
          rateFlag: '',
          taxRate: undefined,
          extends1: '', // 图文详情
          extends2: '', // 产品参数
          extends3: '' // 售后保障
        },
        rules: {
          goodsCode: [{ required: true, message: '请获取商品编码', trigger: 'change' }],
          goodsName: [{ required: true, message: '请输入商品名称', trigger: 'change' }],
          specId: [{ required: true, message: '请选择型号', trigger: 'change' }],
          unitId: [{ required: true, message: '请选择商品单位', trigger: 'change' }],
          cubage: [{ required: true, message: '请输入体积', trigger: 'change' }],
          weight: [{ required: true, message: '请输入重量', trigger: 'change' }],
          cashPledge: [{ required: true, message: '请输入押金', trigger: 'change' }],
          returnPriceType: [{ required: true, message: '请选择退残单价', trigger: 'change' }],
          showIndex: [{ required: true, message: '请输入显示顺序', trigger: 'change' }],
          gdProperty: [{ required: true, message: '请选择商品性质', trigger: 'change' }]
        }
      }
    },
    computed: {
      ...mapGetters([
        'orgList'
      ])
    },
    async created() {
      await Promise.all([this.getTreeData(), this.getSpecListAll()])
    },
    methods: {
      async open(currentGoodsType, row, type) {
        console.log(currentGoodsType)
        this.reset()
        if (currentGoodsType.specialFlag === 1) {
          this.goodsChannel = [
            { value: 4, desc: 'App端（代客,教客下单）' },
            { value: 16, desc: 'App端安检渠道' },
            { value: 32, desc: 'App端配件渠道' },
            { value: 64, desc: '企业端（PC，槽批批发）' }
          ]
          this.goodsChannelOrigin = [
            { value: 4, desc: 'App端（代客,教客下单）' },
            { value: 16, desc: 'App端安检渠道' },
            { value: 32, desc: 'App端配件渠道' },
            { value: 64, desc: '企业端（PC，槽批批发）' }
          ]
        }
        this.row = row
        await this.queryOptionsMap()
        this.getSpecListAll()
        if (type === 'edit') {
          this.temp.returnPriceType = ''
          await this.getDefaultData(row)
        } else {
          if (currentGoodsType.specialFlag === 1) {
            this.temp.saleMode = [4]
          } else {
            this.temp.saleMode = [1, 2, 4, 8]
          }
          if (this.gdStatusMapOrigin) {
            var gdStatusData = []
            JSON.parse(JSON.stringify(this.gdStatusMapOrigin)).forEach(item => {
              item.value = (1 << item.value)
              gdStatusData.push({ value: item.value, desc: item.desc })
            })
            this.gdStatusMap = gdStatusData
            console.log(this.gdStatusMap)
          }
        }
        this.currentGoodsType = currentGoodsType
        if (currentGoodsType.goodsId) this.goodsId = currentGoodsType.goodsId
        this.type = type
        return new Promise(resolve => {
          this.resolve = resolve
          this.visible = true
        })
      },
      // 获取默认数据
      async getDefaultData(temp) {
        const res = await queryGoodsDefaultData({
          goodsId: temp.goodsId
        })
        this.detail = res.data
        if (res.data.goodsInfo) {
          this.temp = Object.assign(this.temp, res.data.goodsInfo, {
            gdStatus: [],
            saleMode: [],
            csmType: []
          })
          this.temp.specId = this.temp.specId ? this.temp.specId : ''
          const goodsOptions = res.data.goodsInfo.options || 0
          this.sys_goods_edit_options_1 = (goodsOptions >> 1 & 0x01) === 1
          this.sys_goods_edit_options_2 = (goodsOptions >> 2 & 0x01) === 1
          this.sys_goods_edit_options_3 = (goodsOptions >> 3 & 0x01) === 1
          this.sys_goods_edit_options_4 = (goodsOptions >> 4 & 0x01) === 1
          this.sys_goods_edit_options_5 = (goodsOptions >> 5 & 0x01) === 1
          this.sys_goods_edit_options_6 = (goodsOptions >> 6 & 0x01) === 1
          const gdStatus = res.data.goodsInfo.gdStatus || 0
          if (this.gdStatusMapOrigin) {
            var gdStatusData = []
            JSON.parse(JSON.stringify(this.gdStatusMapOrigin)).forEach(item => {
              item.value = (1 << item.value)
              gdStatusData.push({ value: item.value, desc: item.desc, checked: (item.value & gdStatus) > 0 })
            })
            gdStatusData.forEach(it => {
              if (it.checked) this.temp.gdStatus.push(it.value)
            })
            this.gdStatusMap = gdStatusData
          }
          // if (res.data.goodsInfo.pricingMode === 2) {
          //   this.goodsChannel.splice(1, 1)
          // }
          if (res.data.goodsInfo.saleMode > 0) {
            this.goodsChannel.forEach(channel => {
              const checked = ((res.data.goodsInfo.saleMode & channel.value) === channel.value)
              channel.checked = checked
            })
          } else if (this.currentGoodsType.gtId === 0) {
            this.goodsChannel[0].checked = true
          }
          this.goodsChannel.forEach(i => {
            if (i.checked) this.temp.saleMode.push(i.value)
          })
          if (res.data.goodsInfo.isPreferential) {
            this.temp.isPreferential = true
          }
          if (res.data.goodsInfo.orgIds) {
            this.temp.radio = '2'
            this.temp.orgIds = res.data.goodsInfo.orgIds && res.data.goodsInfo.orgIds.split(',')
          } else {
            this.temp.radio = '1'
          }
          const csmType = res.data.goodsInfo.csmtype
          if (csmType > 0) {
            const checked = this.userTypeList.filter(item => (csmType & (item.value)) === item.value)
            if (checked && checked.length > 0) this.temp.csmType = checked.map(item => (item.value))
          }
          console.log(this.temp)
        }
      },
      // 获取商品编码
      async getCode() {
        const res = await queryOrgCode({
          codeType: 6
        })
        this.temp.goodsCode = res.data
      },
      // 获取商品型号列表
      async getSpecListAll() {
        const res = await querySpecListAll({
          currentPage: 1, pageSize: 999
        })
        if (res.data.rows) this.specListAll = res.data.rows
      },
      // 查询枚举
      async queryOptionsMap() {
        const [res1, res2, res3, res4, res5] = await Promise.all([mergeAsyncFunc(queryMap, { enumName: 'UnitType' }), queryMap({ enumName: 'GdStatus' }), mergeAsyncFunc(queryMap, { enumName: 'GdProperty' }), mergeAsyncFunc(queryMap, { enumName: 'TaxRateFlag' }),
                                                                  mergeAsyncFunc(queryMap, { enumName: 'CustomerType' })
        ])
        this.unitIdMap = res1.data // 单位
        this.gdStatusMap = res2.data // 商品状态
        this.gdStatusMapOrigin = res2.data
        this.gdPropertyMap = res3.data
        this.taxRateFlagMap = res4.data
        this.userTypeList = res5.data
        // 默认选择全部用户类型
        this.temp.csmType = this.userTypeList.map(item => {
          return item.value
        })
      },
      // 获取所属机构数据
      async getTreeData() {
        const data = this.orgList.map(item => ({
          label: item.name,
          ...item
        }))
        this.treeData = getTreeData(data)
      },
      // 选择所属机构
      selectTreeChange(value) {
        this.orgSNNo = value.orgSNNo
      },
      // 计价方式改变，商品状态和营销渠道的枚举值变化
      priceingModeChange(value) {
        if (value === 1) {
          const gdStatusArr = JSON.parse(JSON.stringify(this.gdStatusMapOrigin))
          const gdStatusData = []
          gdStatusArr.forEach(item => {
            item.value = (1 << item.value)
            if (this.detail.goodsInfo && value === this.detail.goodsInfo.pricingMode) {
              gdStatusData.push({ value: item.value, desc: item.desc, checked: (item.value & this.detail.goodsInfo.gdStatus) > 0 })
            } else {
              gdStatusData.push({ value: item.value, desc: item.desc })
            }
          })
          this.$set(this.temp, 'gdStatus', [])
          this.$set(this.temp, 'saleMode', [])
          this.gdStatusMap = gdStatusData
          this.goodsChannel = JSON.parse(JSON.stringify(this.goodsChannelOrigin))
          gdStatusData.forEach(it => {
            if (it.checked) this.temp.gdStatus.push(it.value)
          })
          // if (this.row.pricingMode === 2) {
          //   this.$set(this.temp, 'gdStatus', [])
          //   this.$set(this.temp, 'saleMode', [])
          // } else {
          //   this.$set(this.temp, 'gdStatus', this.gdStatusMapOrigin.filter(item => (1 << item.value & this.row.gdStatus) > 0).map(it => it.value))
          //   this.$set(this.temp, 'saleMode', this.goodsChannelOrigin.filter(item => (1 << item.value & this.row.saleMode) > 0).map(it => it.value))
          // }
        } else {
          this.$set(this.temp, 'gdStatus', [])
          this.$set(this.temp, 'saleMode', [])
          if (this.detail.goodsInfo && this.detail.goodsInfo.pricingMode === value) {
            this.gdStatusMap = [{ value: 64, desc: '正常', checked: (1 << 6 & this.detail.goodsInfo.gdStatus) > 0 }]
            this.gdStatusMap.forEach(it => {
              if (it.checked) this.temp.gdStatus.push(it.value)
            })
          } else {
            this.gdStatusMap = [{ value: 64, desc: '正常' }]
          }
          // if (this.currentGoodsType.gtName !== '燃气配件') {   付老师说改成specialFlag判断
          if (this.currentGoodsType.specialFlag !== 1) {
            this.goodsChannel = [
              { value: 1, desc: '呼叫中心（CRM,话务下单）' },
              { value: 4, desc: 'App端（代客,教客下单）' },
              { value: 8, desc: '门店（门店下单）' },
              { value: 64, desc: '企业端（PC，槽批批发）' }
            ]
          }
        }
      },
      success() {
        this.$refs.dataForm.validate(valid => {
          if (!valid) {
            this.activeName = 'first'
            this.$message.warning('请将必填信息填写完整')
            return
          }
          if (this.temp.returnPriceType === 2 && !this.temp.returnPrice && this.temp.returnPrice !== 0) {
            this.$message.warning('请输入退单单价')
            return
          }
          const unit = this.unitIdMap.find(item => item.value === this.temp.unitId)
          const spec = this.specListAll.find(item => item.specId === this.temp.specId)
          const params = {
            goodsCode: this.temp.goodsCode,
            goodsName: this.temp.goodsName,
            aliasName: this.temp.aliasName,
            cubage: this.temp.cubage,
            weight: this.temp.weight,
            cashPledge: this.temp.cashPledge,
            deliveryFun: this.temp.deliveryFun,
            floorFun: this.temp.floorFun,
            remark: this.temp.remark,
            exchangeFlag: this.temp.exchangeFlag || 0,
            gdProperty: this.temp.gdProperty,
            showIndex: this.temp.showIndex,
            goodsShortCode: this.temp.goodsShortCode,
            isPreferential: this.temp.isPreferential ? 1 : 0,
            taxRateFlag: this.temp.taxRateFlag,
            taxRate: this.temp.taxRate,
            returnPriceType: this.temp.returnPriceType,
            returnPrice: this.temp.returnPrice,
            goodsId: this.temp.goodsId || 0,
            pricingMode: this.temp.pricingMode,
            unitId: this.temp.unitId,
            unitName: unit.desc,
            percentage: this.temp.percentage || 0.00
          }
          params.saleMode = this.handleVal('saleMode')
          params.gdStatus = this.handleVal('gdStatus')
          params.csmtype = this.handleVal('csmType')
          if (spec) {
            params.specId = this.temp.specId
            params.specAliasCode = spec.specAliasCode
            params.specName = spec.specName
            params.specCode = spec.specCode
          }
          if (this.goodsId === 0) {
            params.gTypeId = this.currentGoodsType.gtId
            params.gtSNNo = this.currentGoodsType.gtSNNo
            params.gtName = this.currentGoodsType.gtName
          }
          params.options |= 1 << 0
          if (this.sys_goods_edit_options_1) {
            params.options |= 1 << 1
          }
          if (this.sys_goods_edit_options_2) {
            params.options |= 1 << 2
          }
          if (this.sys_goods_edit_options_3) {
            params.options |= 1 << 3
          }
          if (this.sys_goods_edit_options_4) {
            params.options |= 1 << 4
          }
          if (this.sys_goods_edit_options_5) {
            params.options |= 1 << 5
          }
          if (this.sys_goods_edit_options_6) {
            params.options |= 1 << 6
          }

          if (this.temp.radio === '2') {
            params.orgIds = this.temp.orgIds.join(',')
          } else {
            params.orgIds = ''
          }
          if (this.$refs.fuEditor1.styleContent.length > 0) params.extends1 = this.$refs.fuEditor1.styleContent
          if (this.$refs.fuEditor2.styleContent.length > 0) params.extends2 = this.$refs.fuEditor2.styleContent
          if (this.$refs.fuEditor3.styleContent.length > 0) params.extends3 = this.$refs.fuEditor3.styleContent
          if (this.type === 'add') {
            this.add(params)
          } else {
            this.edit(params)
          }
        })
      },
      handleVal(key) {
        let k = 0
        if (this.temp[key].length > 0) {
          this.temp[key].forEach(item => {
            k |= Number(item)
          })
        }
        return k
      },
      async add(params) {
        await goodsAdd(params)
        this.resolve()
        this.visible = false
        this.$notify({
          title: '提示',
          message: '新增成功',
          type: 'success',
          duration: 2000
        })
      },
      async edit(params) {
        await goodsAdd(params)
        this.resolve(this.temp)
        this.visible = false
        this.$notify({
          title: '提示',
          message: '更新成功',
          type: 'success',
          duration: 2000
        })
      },
      formatInput(e, name) {
        if (e.target.value) {
          this.temp[name] = Number(e.target.value).toFixed(2)
        }
      },
      reset() {
        this.type = 'add'
        this.activeName = 'first'
        this.additionTab = 'first'
        this.temp = {
          goodsCode: '',
          goodsName: '',
          unitId: '',
          aliasName: '',
          cubage: 0,
          weight: 0,
          percentage: 0.00,
          specId: '',
          pricingMode: 1,
          deliveryFun: 0,
          floorFun: 0,
          cashPledge: 0,
          returnPrice: 0,
          gdStatus: [],
          gdProperty: 1,
          saleMode: [],
          csmType: [],
          checkList: [],
          radio: '1',
          returnPriceType: '',
          orgIds: [],
          showIndex: 999,
          remark: '',
          exchangeFlag: 2,
          goodsShortCode: '',
          isPreferential: false,
          taxRateFlag: 1,
          rateFlag: '',
          taxRate: undefined,
          extends1: '', // 图文详情
          extends2: '', // 产品参数
          extends3: '' // 售后保障
        }
        this.goodsChannel = [
          { value: 1, desc: '呼叫中心（CRM,话务下单）' },
          { value: 2, desc: '移动端（公众号,小程序）' },
          { value: 4, desc: 'App端（代客,教客下单）' },
          { value: 8, desc: '门店（门店下单）' },
          { value: 64, desc: '企业端（PC，槽批批发）' }
        ]
        this.goodsChannelOrigin = [
          { value: 1, desc: '呼叫中心（CRM,话务下单）' },
          { value: 2, desc: '移动端（公众号,小程序）' },
          { value: 4, desc: 'App端（代客,教客下单）' },
          { value: 8, desc: '门店（门店下单）' },
          { value: 64, desc: '企业端（PC，槽批批发）' }
        ]
        this.userTypeList = [
          { value: 1, desc: '居民用户' },
          { value: 2, desc: '非居民用户' },
          { value: 4, desc: '工业用户' },
          { value: 8, desc: '瓶批用户' },
          { value: 16, desc: '槽批用户' }
        ]
        this.$nextTick(() => {
          this.$refs.dataForm.clearValidate()
        })
        this.visible = false
      },
      doCheck(val) {
        this.temp.orgIds = val
      }
    }
  }
</script>

<style lang="scss" scoped>
.form {
  display: flex;
  flex-wrap: wrap;
  & /deep/ .el-form-item {
    width: 50%;
    padding-right: 10px;
    .el-form-item__content > .el-select {
      width: 100%;
    }
  }
  .block {
    width: 100%;
  }
}
.info-title {
  display: flex;
  align-items: center;
  margin-top: 10px;
  margin-bottom: 20px;
  .title-icon {
    display: inline-block;
    width: 4px;
    height: 18px;
    margin-right: 6px;
    background: $themeColor;
  }
  span {
    font-weight: 700;
    color: $themeColor;
  }
}
</style>
